def singleton(cls):
    instances = {}

    def get_instance(*args, **kwargs):
        if cls not in instances:
            instances[cls] = cls(*args, **kwargs)
        return instances[cls]

    return get_instance


@singleton
class Test:
    pass


test1 = Test()
test2 = Test()

assert test1 is test2, "不是单例"
